package cn.pinming.chyn.tools.exception;

/**
 * Create by WangSJ on 2019/03/13
 * 基本异常类型
 * 所有自定义异常，都应该实现ResultCode接口，拦截器中会根据异常类型动态返回错误信息
 */
public class ChynException extends RuntimeException implements ResultCode {

    protected int code;
    protected String msg;

    public ChynException(String msg){
        this(ChynResultCode.ERR , msg) ;
    }

    public ChynException(ResultCode resultCode){
        this(resultCode , resultCode.getMsg()) ;
    }

    public ChynException(ResultCode resultCode,String msg){
        super(msg);
        if (resultCode != null) {
            this.code = resultCode.getCode();
            this.msg = msg;
        }
    }

    @Override
    public int getCode() {
        return this.code;
    }

    @Override
    public String getMsg() {
        return this.msg;
    }

    /**
     * 自定义异常将不再爬取堆栈，提高异常性能
     */
    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }
}
